package com.atguigu.baku.controller;


import com.atguigu.baku.entity.Company;
import com.atguigu.baku.entity.PageBean;
import com.atguigu.baku.service.CompanyService;
import com.atguigu.baku.vo.AreaCityVo;
import com.atguigu.baku.vo.CompanyListQuery;
import com.atguigu.baku.vo.CompanyListVo;
import com.atguigu.baseservice.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 企业主表（工商信息、账户信息） 前端控制器
 * </p>
 *
 * @author dayouzi
 * @since 2022-11-09
 */
@Api(description = "八库管理")
@RestController
@RequestMapping("/baku/laowu/company")
@CrossOrigin
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @ApiOperation(value = "根据id查询")
    @GetMapping("/{id}")
    public R getById(@ApiParam(name = "id", value = "id", required = true)
                           @PathVariable String id) {
        Company company = companyService.getCompanyById(id);
        return R.ok().data("item", company);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping("/{page}/{pageSize}")
    public R getById(@ApiParam(name = "page", value = "当前页码", required = true)
                     @PathVariable Integer page,
                     @ApiParam(name = "pageSize", value = "每页记录数", required = true)
                     @PathVariable Integer pageSize,
                     @ApiParam(name = "companyListQuery", value = "查询对象", required = false)
                     @RequestBody CompanyListQuery companyListQuery) {
        PageBean<CompanyListVo> pageBean = companyService.getCompanyList(page, pageSize, companyListQuery);
        return R.ok().data("total", pageBean.getTotal()).data("rows", pageBean);
    }

    @ApiOperation(value = "清洗数量查询")
    @GetMapping("/isClean")
    public R getIsCleanNum() {
        Map<String, Long> isCleanMap = companyService.getIsCleanNum();
        return R.ok().data("isCleanNum", isCleanMap.get("isCleanNum")).data("isNotCleanNum", isCleanMap.get("isNotCleanNum"));
    }

}

